package com.sky.controller.admin;

import com.sky.annotate.DropRedis;
import com.sky.dto.CategoryDTO;
import com.sky.dto.CategoryPageQueryDTO;
import com.sky.entity.Category;
import com.sky.result.Result;
import com.sky.service.CategoryService;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.web.bind.annotation.*;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.function.Function;

@RestController
@RequestMapping("/admin/category")
public class CategoryController {

    @Autowired
    CategoryService categoryService;

    @DropRedis
    @PostMapping
    public Result AddCategory(@RequestBody CategoryDTO categoryDTO){


        Category category = new Category();
        BeanUtils.copyProperties(categoryDTO,category);
        return categoryService.AddCategory(category);
    }
    // category/page?page=1&pageSize=10

    @GetMapping("/page")
    public Result GetPage(CategoryPageQueryDTO categoryPageQueryDTO){
        Result result = categoryService.GetPage(categoryPageQueryDTO);
        return result;
    }

    @DropRedis
    @DeleteMapping
    public Result DeleteById(Integer id){
        return categoryService.DeleteById(id);

    }

    @DropRedis
    @PutMapping
    public Result Update(@RequestBody CategoryDTO categoryDTO){

        categoryService.Update(categoryDTO);
        return Result.success();
    }
    @PostMapping("/status/{status}")
    @DropRedis
    public Result Update(@PathVariable Integer status,Integer id){
        return categoryService.Update(status,id);
    }

    //  category/list?type=1

    // 返回分类
    @GetMapping("/list")
    public Result GetType(Integer type){
       return categoryService.getType(type);
    }

    //dish


}
